<?php
/**
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 */
	defined ('IN_AGORA') or die;

	class TaskController extends AgoraProfileController
	{
	    	    
		function _default()
		{
			if (!empty($this->user['birthday'])) {
				$birthday = getdate($this->user['birthday']);


				$this->view->assign('birthday',array(
						'day'	=>	$birthday['mday'],
						'month'	=>	$birthday['mon'],
						'year'	=>	$birthday['year']
					));
			} else {
				$this->view->assign('birthday',array('day' => 0, 'month' => 0, 'year' => 0));
			}

			$ban_model = &Model::getInstance('BanModel');
			$this->user['banned'] = $ban_model->isBanned($this->user['username']);
			if ($this->user['banned']) {
				$ban = $ban_model->load($this->user['username'],'username');
				$this->view->assign('ban',$ban);
			}

			$warning_model = &Model::getInstance('WarningModel');
			$warnings = $warning_model->loadByUser($this->user['id']);

			$this->view->assign('warnings',$warnings);
		}


		function save()
		{
			$form = Agora::getPostVar('form',array());
			if (!isset($form['hide_age'])) $form['hide_age'] = 0;
			
			$form['url'] = htmlspecialchars($form['url']);
			$form['latitude'] = (float)$form['latitude'];
			$form['longitude'] = (float)$form['longitude'];
			
			
			if (checkdate(
				$form['birthday-month'],
				$form['birthday-day'],
				$form['birthday-year'])) {

				$form['birthday'] = mktime(0,0,0, $form['birthday-month'], $form['birthday-day'], $form['birthday-year']);
			} else {
				$form['birthday'] = 0;
			}
			unset($form['birthday-month']);
			unset($form['birthday-year']);
			unset($form['birthday-day']);
			if ($form['url']) {
				if(!stristr($form['url'],"http://")){
					$form['url'] = "http://" . $form['url'];
					JError::raiseNotice( 0, JText::_('Add http' ) );
				}
			}
			JPluginHelper::importPlugin( 'agora' );
			$dispatcher =& JDispatcher::getInstance();
			$options= new JObject; 
			$options->user = &$this->agora_user;
			$options->form = &$form;

			$plg_arguments = array(&$options);
			
			$plg_result =  $dispatcher->trigger( 'onBeforeProfileSave',$plg_arguments) ;
			$this->model->edit($this->user_id,$form);
			$plg_result =  $dispatcher->trigger( 'onAfterProfileSave',$plg_arguments) ;
			$this->redirect();
		}
	}
?>
